package com.xmg.lru;

import java.util.LinkedHashMap;
import java.util.Map;

public class LinkedHashMapDemo<K,V> extends LinkedHashMap {
    private int cap;
    public LinkedHashMapDemo(int cap){
        super(cap,0.75f,true);
        this.cap = cap;
    }

    @Override
    protected boolean removeEldestEntry(Map.Entry eldest) {
        return this.size()>cap;
    }

    public static void main(String[] args) {
        LinkedHashMapDemo<Integer,Integer> lru = new LinkedHashMapDemo<>(3);
        lru.put(1,2);
        lru.put(2,3);
        lru.put(3,4);
        System.out.println(lru.keySet());
        lru.get(1);

        lru.put(4,5);
        System.out.println(lru.keySet());

    }
}
